/*
 * Copyright (c) 2020 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.andkulikov.transitionseverywhere.slice;


import com.andkulikov.transitionseverywhere.ResourceTable;
import com.transitionseverywhere.Rotate;
import com.transitionseverywhere.Transition;
import com.transitionseverywhere.TransitionManager;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.*;
import ohos.utils.LightweightMap;

import java.util.ArrayList;

public class RotationSlice extends AbilitySlice implements Component.ClickedListener {

    private DependentLayout mDlViewRoot;
    private Image mIvTransition;
    private Rotate rotate;

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        ComponentContainer layout = (ComponentContainer) LayoutScatter.getInstance(this).
                parse(com.transitionseverywhere.ResourceTable.Layout_slice_rotate, null, false);
        mDlViewRoot = (DependentLayout) layout.findComponentById(ResourceTable.Id_dlViewRoot);
        Object tagMap = new LightweightMap<String, ArrayList<Transition>>();
        mDlViewRoot.setTag(tagMap);
        mIvTransition = (Image) layout.findComponentById(ResourceTable.Id_ivRotate);
        mIvTransition.setClickedListener(this::onClick);
        rotate = new Rotate();
        super.setUIContent(layout);
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_ivRotate:
                TransitionManager.beginDelayedTransition(mDlViewRoot, rotate);
                break;
        }
    }
    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
